package com.lesso.yzh.sunflower.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.yzh.sunflower.core.ApiResponse;
import com.lesso.yzh.sunflower.pojo.dto.EmployeeDTO;
import com.lesso.yzh.sunflower.pojo.dto.EmployeeQueryDTO;
import com.lesso.yzh.sunflower.pojo.dto.EmployeeUpdateDTO;
import com.lesso.yzh.sunflower.pojo.vo.EmployeeVO;
import com.lesso.yzh.sunflower.service.IEmployeeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工基础信息 前端控制器
 * </p>
 *
 * @author yzh
 * @since 2025-07-02
 */
@RestController
@RequestMapping("/base/employee")
public class EmployeeController {
    @DubboReference
    private IEmployeeService employeeService;

    @PostMapping
    public ApiResponse<Integer> save(@RequestBody EmployeeDTO dto) {
        return ApiResponse.ok("success", employeeService.save(dto));
    }

    @GetMapping("/page")
    public ApiResponse<Page<EmployeeVO>> page(EmployeeQueryDTO dto) {
        return ApiResponse.ok("success", employeeService.page(dto));
    }

    @GetMapping("/update")
    public ApiResponse<Integer> update(@RequestBody EmployeeUpdateDTO dto) {
        return ApiResponse.ok("success",employeeService.update(dto));
    }
    @GetMapping("/custom/page")
    public ApiResponse<Page<EmployeeVO>> customPage(EmployeeQueryDTO dto) {
        return ApiResponse.ok("success", employeeService.customPage(dto));
    }

    @DeleteMapping
    public ApiResponse<Object> delete(@RequestParam("id") Long id) {
        Assert.notNull(id, "id不能为空");
        if (id < 0) {
            throw new RuntimeException("id不能小于0");
        }
        employeeService.deleteById(id);
        return ApiResponse.ok();
    }
}
